home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3955 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.1 KB  |  51 lines

  1. Path: oxy.rust.net!usenet
  2. From: ebennett@rust.net
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Visual C++ 4.0 lacking initializers?
  5. Date: Fri, 26 Jan 1996 19:12:49 GMT
  6. Organization: Rust Net - High Speed Internet in Detroit  810-642-2276
  7. Message-ID: <4eauhh$47v@oxy.rust.net>
  8. References: <31049C46.A26@oz.is>
  9. NNTP-Posting-Host: liv-3.rust.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Hßlfdan Ingvarsson <halfdan@oz.is> wrote:
  13.  
  14. >Is it me or is this sort of code not possible with VC++ 4.0? 
  15.  
  16. >// Declarations of class Foo
  17.  
  18. >// VC++ Complains about the line below with the error
  19. >// error C2436: '__ctor' : cannot initialize member functions
  20. >Foo::Foo(void) : Foo::Foo(10) {}
  21.  
  22. >Foo::Foo(x)
  23. >{
  24. >  // Some stuff
  25. >}
  26.  
  27. Here is yet another way to do this that I did not think of when I
  28. posted my first response to this.  What this is really attempting to
  29. mimmick is a constructor with a default parameter.
  30.  
  31.   class Foo
  32.   {
  33.     public:
  34.        Foo (int x = 10);
  35.        ....
  36.   };
  37.  
  38.   Foo::Foo (int x)
  39.   {
  40.      // do initialization
  41.   };
  42.  
  43. This results in the following:
  44.  
  45.   Foo a;      // a is initialized with the value 10
  46.   Foo b(5);  // b is initialized with the value 5
  47.  
  48. Earl
  49.  
  50.  
  51.